import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenThrTouter, ExamineButton } from '../Common/options'

export const SecurityDetails = async ({ OptionsEvent, oneData, Permission, actionRef }) => {
    const data = {
        hideInSearch: true,
        pageSize: 10,
        initialValues: { securityUuid: oneData?.uuid },
        params: { pageIndex: 1, securityUuid: oneData.uuid },
        get: API_LIST()['getSecurityDetail'],
        added: 'posSecurityDetail',
        modify: `putSecurityDetail`,
        options: [
            oneData.auditStatus === 1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增整改信息" />
            ),
        ],
        columns: [
            // 名称 描述 日期
            commonTableList.uuid,
            {
                dataIndex: 'securityUuid',
                title: 'securityUuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            { ...commonTableList.tableName, title: '整改主题' },
            {
                dataIndex: 'description',
                title: '整改描述',
                valueType: 'input',
                rules: true,
                ellipsis: true,
                width: 250,
            },
            {
                dataIndex: 'securityDetailDate',
                title: '整改日期',
                valueType: 'Date',
                rules: true,
                width: 250,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, handling } = record
                    return [
                        <OpenThrTouter
                            key="thrOne"
                            title="附件详情"
                            twoTitle="整改详情信息"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'SecurityDetailAttachment',
                                actionRef,
                                Permission,
                                twoData: record,
                            }}
                        />,

                        handling === 1 && (
                            <ExamineButton
                                key="one"
                                title="提交待审"
                                data={{
                                    actionRef,
                                    OptionsEvent,
                                    url: 'putSecurityDetailSubmit',
                                    smallTitle: '提交安全巡检',
                                }}
                                options={[
                                    { title: '接受', type: 'primary', emit: { path: [uuid] } },
                                    { title: '取消', type: 'link', emit: 'off' },
                                ]}
                            />
                        ),
                        oneData.auditStatus === 1 && handling === 1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        oneData.auditStatus === 1 &&
                            handling === 1 &&
                            Permission.findIndex(v => v.uuid === '270bb48e-4e64-4276-b898-00ea14eaaa59') !== -1 && (
                                <DelDataButton
                                    OptionsEvent={OptionsEvent}
                                    key="del"
                                    title="删除"
                                    url="SecurityDetail"
                                    uuid={uuid}
                                />
                            ),
                    ]
                },
            },
        ],
    }

    return data
}
